package com.yuntian.service.Impl;

import com.yuntian.entity.Admin;
import com.yuntian.exception.BaseException;
import com.yuntian.mapper.AdminMapper;
import com.yuntian.properties.JwtProperties;
import com.yuntian.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.time.LocalDateTime;

@Service
public class AdminServiceImpl  implements AdminService {

    @Autowired
    private AdminMapper adminMapper;



   /* @Override
    public Admin login(Admin admin) {
        String adminName = admin.getAdminName();
        String adminPass = admin.getAdminPass();

        Admin adminEntity = adminMapper.getByUserName(adminName);

        adminPass = DigestUtils.md5DigestAsHex(adminPass.getBytes());
        if (adminEntity == null){
            return null;
        }
        if (!adminEntity.getAdminPass().equals(adminPass)){
            return null;
        }

        return adminEntity;
    }*/

    @Override
    public void save(Admin admin) {
        Admin admin1 =  adminMapper.getByAdminName(admin.getAdminName());
        if (admin1 != null){
            throw new BaseException("用户名已存在");
        }
        admin.setCreateTime(LocalDateTime.now());
        //密码加密
        String adminPass = admin.getAdminPass();
        admin.setAdminPass(DigestUtils.md5DigestAsHex(adminPass.getBytes()));

        adminMapper.insert(admin);
    }
}
